package com.bigfish.gbs.controller;

import com.bigfish.gbs.dto.GoodsVO;
import com.bigfish.gbs.dto.Result;
import com.bigfish.gbs.entity.GoodsTemp;
import com.bigfish.gbs.enums.ResultEnum;
import com.bigfish.gbs.service.GoodsService;
import com.bigfish.gbs.util.ResultUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author Joycessh
 * @Description
 * @Date 12/20/18 9:50 AM
 */
@Api(value = "公共接口", description = "不需要授权认证就能请求的接口")
@RestController
@RequestMapping("/common")
public class CommonContoller extends BasicAction {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private GoodsService goodsService;

    @ApiOperation(value = "获取商品列表", httpMethod = "GET")
    @GetMapping("/goods")
    public Result getGoods(@RequestParam Integer currentPage,
                           @RequestParam Integer pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        List<GoodsVO> list = goodsService.getGoodsList();
        PageInfo pageInfo =new PageInfo(list);
        return ResultUtil.retFormat(ResultEnum.SUCCESS).addData("goods", pageInfo);
    }

    @ApiOperation(value = "获取商品列表", httpMethod = "GET")
    @GetMapping("/goods/list")
    public Result getGoods() {
        byte i = 0;
        List<GoodsVO> list = goodsService.getGoodsByStatus(i);

        return ResultUtil.retFormat(ResultEnum.SUCCESS).addData("goods", list);
    }
}
